// Promise.all方法
Promise.prototype._all = function(promiseList) {
  const result = [];
  return new Promise((resolve, reject) => {
    for(let i = 0; i < promiseList.length; i++) {
      const promise = promiseList[i]();
      promise.then(res => {
        result.push(res);
        if(result.length === promiseList.length) {
          resolve(result);
        }
      }, err => {
        return reject(err);
      })
    }
  })
}

// Promise.race方法
Promise.prototype._race = function(promiseList) {
  return new Promise((resolve, reject) => {
    for(let i = 0; i < promiseList.length; i++) {
      const promise = promiseList[i]();
      promise.then(res => {
        return resolve(res);
      }, err => {
        return reject(err);
      })
    }
  })
}

// Promise.finally方法
Promise.prototype._finally = function(fn) {
  return this.then(res => {
    Promise.resolve(fn()).then(() => {
      return res
    }, err => {
      Promise.reject(fn()).then(() => {
        throw err
      })
    })
  })
}